package com.xiezc.dht.util;

import java.util.concurrent.ThreadFactory;

/**
 * 线程工厂
 *
 * @author wb-xzc291800
 */
public class DefaultThreadFactory implements ThreadFactory {

    private ThreadGroup threadGroup;

    public DefaultThreadFactory(ThreadGroup threadGroup) {
        this.threadGroup = threadGroup;
    }

    public DefaultThreadFactory(String threadGroupName) {
        this(new ThreadGroup(threadGroupName));
    }

    public Thread newThread(String name, Runnable r) {
        Thread thread = this.newThread(r);
        thread.setName(name);
        return thread;
    }

    @Override
    public Thread newThread(Runnable r) {
        Thread thread = new Thread(threadGroup, r);
        return thread;
    }
}